package com.carbohydrate42.kotlin_compose_demo.compose

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.tooling.preview.Preview
import com.carbohydrate42.kotlin_compose_demo.util.QrCodeAndBarCodeUtil


@OptIn(ExperimentalMaterial3Api::class)
@Preview(showBackground = true, showSystemUi = true)
@Composable
fun TryBarcodeGenerator() {
    var code by remember {
        mutableStateOf("123123")
    }

    Column {

        Text(text = code.ifBlank { "empty" })

        Image(
            bitmap = QrCodeAndBarCodeUtil
                .getQrcodeBitMap(code.ifBlank { "empty" }, 600, 600)
                .asImageBitmap(),

            contentDescription = code
        )

        TextField(
            value = code,
            onValueChange = {
                code = it
            }
        )
    }
}